<DOCTYPE html>
    <html>

    <head>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="renderer" content="webkit">
        <base href="${rc.contextPath}/">
        <title>企业管理</title>

    <#include "/commons/stylesheets.ftl">

        <link href="jquery-select2/select2.min.css" rel="stylesheet">
        <link href="/layer/skin/layer.css" rel="stylesheet">


    <#include "/commons/scripts.ftl">

        <script type="text/javascript">
            function saveForm() {
                var form = $("#form");
                if (!form.valid()) {
                    return;
                }
                $.getJSON("company/save", serializeForm(form), function (resp) {
                    if (resp.resultCode == "success") {
                        layer.alert('保存成功', function () {
                            console.log("###");
                            window.parent.refreshTable();
                            console.log(window.parent.refreshTable)
                            window.parent.layer.closeAll();

                        });
                    } else if (resp.resultCode == "companyNameExist") {
                        layer.msg('企业名称已经存在');
                    } else {
                        layer.msg('保存失败');
                    }
                });
            }

            function pageInit() {
                $("#form").validate();
                var companyTypeInput = $(":input[name='companyType']");
                companyTypeInput.val(companyTypeInput.attr("value"));
            }


        </script>
    </head>

    <body>
    <div class="container-fluid">

        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <form class="form-horizontal m-t" id="form">
                            <#include "form.ftl">

                                <div class="form-group">
                                    <div class="col-xs-9 col-xs-offset-3">
                                        <button class="btn btn-primary" type="button"
                                                onclick="saveForm()">保存
                                        </button>
                                        <button class="btn btn-white" type="button"
                                                onclick="window.parent.layer.closeAll()">取消
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="jquery-select2/select2.min.js"></script>
    <script src="js/app.js"></script>
    <script src="layer/layer.js"></script>


    <script src="js/plugins/validate/jquery.validate.min.js"></script>
    <script src="js/plugins/validate/messages_zh.min.js"></script>
    <script>
        $.validator.setDefaults({
                                    highlight: function (a) {
                                        $(a).closest(".form-group").removeClass("has-success")
                                                .addClass("has-error")
                                    }, success: function (a) {
                a.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (a, b) {
                if (b.is(":radio") || b.is(":checkbox")) {
                    a.appendTo(b.parent().parent().parent())
                } else {
                    a.appendTo(b.parent())
                }
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
                                });

    </script>


    </body>

    </html>